using System.Threading.Tasks;
using UnityEngine;
using System.Threading;

namespace EntityKit.Runtime
{
    public interface IAssetLoader
    {
        /// <summary>
        /// 同步加载资源
        /// </summary>
        /// <param name="location">资源路径</param>
        /// <typeparam name="T">资源类型</typeparam>
        /// <returns>资源</returns>
        T LoadAssetSync<T>(string location) where T : Object;

        /// <summary>
        /// 异步加载资源
        /// </summary>
        /// <param name="location">资源路径</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <typeparam name="T">资源类型</typeparam>
        /// <returns>资源</returns>
        Task<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken) where T : Object;

        /// <summary>
        /// 异步实例化GameObject
        /// </summary>
        /// <param name="location">GameObject路径</param>
        /// <param name="parent">父级</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns></returns>
        Task<GameObject> InstantiateGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken);

        /// <summary>
        /// 同步实例化GameObject
        /// </summary>
        /// <param name="location">GameObject路径</param>
        /// <param name="parent">父级</param>
        /// <returns></returns>
        GameObject InstantiateGameObjectSync(string location, Transform parent);

        /// <summary>
        /// 卸载未使用的资源
        /// </summary>
        void UnloadUnusedAssets();
    }
}